package CI.aufgabe2.cip.mynodes;

import CI.aufgabe2.cip.SymbolTable;
import CI.aufgabe2.cip.base.AbstractDescr;

public class MyModuleNode extends MyAbstractNode{


	private static final long serialVersionUID = 1L;
	public final MyIdNode ident;
	public final MyDeclarationsNode dec;
	public final MyStatementSequenceNode stseq;
	public final MyIdNode ident2;
	
	public MyModuleNode (MyIdNode i, MyDeclarationsNode d, MyStatementSequenceNode ss, MyIdNode i2){
		ident = i;
		dec = d;
		stseq = ss;
		ident2 = i2;
	}
	
	@Override
	public void print() {
		trace("ModuleNode ");
		if(ident != null)
		ident.print();
		
		if(dec != null)
		dec.print();
		
		if(stseq != null)
		stseq.print();
		
		if(ident2 != null)
		ident2.print();
		
		unindent();
	}
	
	
	public AbstractDescr compile(SymbolTable sym) {
		int label = getNextLabelNumber();
		dec.compileConst(sym);
		write("JMP, " + label);
		dec.compile(sym);
		write("LABEL, " + label);
		write("PUSHI, "+ dec.getSize());
		write("SETSP");
		stseq.compile(sym);
		write("STOP");
		
		return null;
	}

}
